<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="csrf-token" content="{{csrf_token()}}">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="{{URL::asset('resources/xadmin/css/font.css')}}">
    <link rel="stylesheet" href="{{URL::asset('resources/xadmin/css/xadmin.css')}}">
    <link rel="stylesheet" href="{{URL::asset('resources/xadmin/lib/layui/css/layui.css')}}">

    <script src="{{URL::asset('resources/xadmin/lib/layui/layui.js')}}" charset="utf-8"></script>
    <script type="text/javascript" src="{{URL::asset('resources/xadmin/js/xadmin.js')}}"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->


</head>
<body>
<!-- <div class="x-nav">
          <span class="layui-breadcrumb">
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div> -->





<div class="layui-fluid layui-container" >
            <div class="layui-row ">

                <form class="layui-form " >
                @foreach($data as $key =>$val)
               

                  <div class="layui-form-item">
                      <label for="username" class="layui-form-label">
                          <span class="x-red">*</span>登录名
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="username" name="username" value="{{$val->username}}" required="" lay-verify="required|username"
                          autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>将会成为您唯一的登入名
                      </div>
                  </div>

                    <!-- 这里title是在网页上显示的数据，value是用Ajax发送的实际的值 -->
                    <div class="layui-form-item">
                        <label class="layui-form-label" value="{{$val->gender}}"><span class="x-red">*</span>性别</label>
                        <div class="layui-input-block">
                        @if($val->gender==1)<input type="radio" name="gender" value="1" title="男"  checked=""><input type="radio" name="gender" value="2" title="女" >
                        <input type="radio" name="gender" value="3" title="保密" >
                        @elseif($val->gender==2)<input type="radio" name="gender" value="1" title="男"  ><input type="radio" name="gender" value="2" title="女" checked=""><input type="radio" name="gender" value="3" title="保密" >
                        @else<input type="radio" name="gender" value="1" title="男"  ><input type="radio" name="gender" value="2" title="女" ><input type="radio" name="gender" value="3" title="保密" checked="">
                        
                        <!-- <input type="radio" name="gender" value="1" title="男"  > -->
                        <!-- <input type="radio" name="gender" value="2" title="女" >
                        <input type="radio" name="gender" value="3" title="保密" > -->
                        @endif
                        </div>
                    </div>

                  <div class="layui-form-item">
                      <label for="phone" class="layui-form-label">
                          <span class="x-red">*</span>联系方式
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="phone" name="mobile" required="" lay-verify="phone"
                          autocomplete="off" class="layui-input" value="{{$val->mobile}}">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>请填写正确的手机号，方便我们联系您
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_email" class="layui-form-label">
                          <span class="x-red">*</span>邮箱
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="L_email" name="email" required="" lay-verify="email"
                          autocomplete="off" class="layui-input" value="{{$val->email}}">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>
                      </div>
                  </div>
                  <div class="layui-form-item" >
                      <label class="layui-form-label"><span class="x-red">*</span>角色</label>
                      <div class="layui-input-block">
                      <div  id="role_id" value="{{$val->role_id}}" style="display:none">{{$val->role_id}}</div>
                        <input type="radio" name="role_id" value="1" title="超级管理员" checked="">
                        <input type="radio" name="role_id" value="2" title="编辑人员">
                        <input type="radio" name="role_id" value="3" title="保安" ><br >
                        <input type="radio" name="role_id" value="4" title="白干员工" >
                        <input type="radio" name="role_id" value="5" title="宣传人员" >
                        <input type="radio" name="role_id" value="6" title="网站会员" >
                      </div>
                  </div>
                 

                  <div class="layui-form-item">
                      <label for="L_pass" class="layui-form-label">
                          <span class="x-red">*</span>密码
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" id="L_pass" name="password" required="" lay-verify="pass"
                          autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          6到12个字符
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                          <span class="x-red">*</span>确认密码
                      </label>
                      <div class="layui-input-inline"><!-- 提交的时候只需要提交密码就可以 -->
                          <input type="password" id="L_repass" /*name="repass"*/ required="" lay-verify="repass"
                          autocomplete="off" class="layui-input">
                      </div>
                  </div>
                <div class="layui-input-item">
                  <div class="layui-input-inline">
                        <label class="layui-form-label">是否启用</label>
                        <div class="layui-input-block">
                        <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|不启用" >
                        </div>
                 </div>
<!-- 
                 <div class="layui-btn-group">
                    <div class="layui-input-inline">
                        <div class="layui-input-block">
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>

                    <div class="layui-input-inline">
                        <label for="L_repass" class="layui-form-label">
                        </label>
                        <button  class="layui-btn" lay-filter="add" lay-submit="">
                            确定修改
                        </button>
                    </div>
                  </div> -->

                <div class="layui-input-inline">

                    <div class="layui-btn-group">
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        
                            <label for="L_repass" class="layui-form-label">
                            </label>
                            <button  class="layui-btn" lay-filter="add" lay-submit="">
                                确定修改
                            </button>
                        </div>
                </div> 

                </div>
                @endforeach
              </form>

            </div>
        </div>


</body>
<script>

layui.use(['form', 'layer'],function() {

        $ = layui.jquery;
        var form = layui.form,
        layer = layui.layer;

        //自定义验证规则
        form.verify({

            
            username: [/(.+){2,12}$/,'用户名最少也得俩字啊'],
            pass: [/(.+){6,12}$/, '密码必须6到12位'],
            repass: function(value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });
        //监听radio单选,layui监听事件不如用jq一句话获得
        // form.on('radio(role_id)', function(data){
        //     console.log(data.elem); //得到radio原始DOM对象
        //     console.log(data.value); //被点击的radio的value值
        //     var role_id=data.value;
        // });  

        //监听提交
        form.on('submit(add)',
        function(data) {
            // console.log(data);
            // console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
            // console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
            // console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            
            //console.log($('input[name="gender"]:checked').val());
            console.log(data.field.status);
            if(data.field.status=='on')data.field.status='2';
            else data.field.status='1';
            
            
            console.log(data.field)
            console.log({{$id}})
            //发异步，把数据提交给php
            $.ajax({
            url:'{{URL::action('Admin\ManagerController@edit',['id'=>$id])}}',
            type:'post',
            data:{edit_data:data.field},
            headers : {
            'X-CSRF-TOKEN' : $("meta[name='csrf-token']").attr('content')
            },
            beforeSend:function () {
                this.layerIndex = layer.load(0, { shade: [0.5, '#393D49'] });
            },
            success:function(data){
                if(data.status=='error'){
                    layer.msg('Error',{
                        icon:5//失败的表情
                        ,time:1000
                    })
                    //return ;
                }else{
                    layer.msg('Successful Edit!',{
                        icon:6,//成功的表情
                        time:1000
                    },function(){
                     xadmin.father_reload();
                     layer.close(this.layerIndex);
                    //obj.del();
                    });
                }
            },
            complete:function(){
                layer.close(this.layerIndex);
            }
        })
            layer.alert("修改成功", {
                icon: 6
            },
            function() {
                //关闭当前frame
                xadmin.close();

                // 可以对父窗口进行刷新 
                xadmin.father_reload();
            });
            return false;
});


});
   

</script>

</html>